package com.lkc.service.impl;

import com.lkc.annotation.LogMethod;
import com.lkc.bean.Categories;
import com.lkc.mapper.CategoriesDao;
import com.lkc.service.CategoriesService;
import com.lkc.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoriesServiceImpl implements CategoriesService {

    @Autowired
    private CategoriesDao categoriesDao;

    @Override
    @LogMethod(serviceName = "分类服务", recordParam = true, recordReturn = true)
    public Categories add(Categories categories) {
        categoriesDao.add(categories);
        return categoriesDao.one(categories.getCategoryId());
    }

    @Override
    @LogMethod(serviceName = "分类服务", recordParam = true, recordReturn = true)
    public int del(Integer categoryId) {
        return categoriesDao.del(categoryId);
    }

    @Override
    @LogMethod(serviceName = "分类服务", recordParam = true, recordReturn = true)
    public Categories edit(Categories categories) {
        categoriesDao.edit(categories);
        return categoriesDao.one(categories.getCategoryId());
    }

    @Override
    @LogMethod(serviceName = "分类服务", recordParam = true, recordReturn = true)
    public Categories one(Integer categoryId) {
        return categoriesDao.one(categoryId);
    }

    @Override
    @LogMethod(serviceName = "分类服务", recordParam = true, recordReturn = false)
    public List<Categories> all(Categories categories) {
        return categoriesDao.all(categories);
    }

    @Override
    @LogMethod(serviceName = "分类服务", recordParam = true, recordReturn = false)
    public void page(Page page, Categories categories) {
        int count = categoriesDao.pageCount(categories);
        Object data = categoriesDao.page(page, categories);
        page.setCount(count);
        page.setData(data);
    }
}
